package a51qindian.com.comprehensive.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.li.utils.TransformUtil;
import com.li.widget.DoubleTextView;

import java.util.List;

import a51qindian.com.comprehensive.Const;
import a51qindian.com.comprehensive.R;
import a51qindian.com.comprehensive.model.Commission;
import a51qindian.com.comprehensive.model.Withdraw;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Author: Li
 * Date: 2017/9/20 0020
 * Description: 收支适配器   包含：分润 以及  提现
 */

public class CommissionAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {


    private LayoutInflater mInflater;
    private String mType;
    private List<Commission> mCommissionList;
    private List<Withdraw> mWithdrawList;

    public CommissionAdapter(Context context, String type) {
        mType = type;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (mType.equals(Const.TYPE_INCOME)) {
            View view = mInflater.inflate(R.layout.item_commission, parent, false);
            return new CommissionHolder(view);
        } else {
            View view = mInflater.inflate(R.layout.item_crash_detail, parent, false);
            return new CrashHolder(view);
        }
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        if (holder instanceof CommissionHolder) {
            CommissionHolder commissionHolder= (CommissionHolder) holder;
            Commission commission=mCommissionList.get(position);
            commissionHolder.mTxtCommissionMoney.setTxtRight(commission.getMoney());
            commissionHolder.mTxtCommissionRemark.setTxtRight(commission.getDesc());
            commissionHolder.mTxtCrashTime.setTxtRight(TransformUtil.timeFormat(commission.getAdd_time()));

        }else {
            CrashHolder crashHolder= (CrashHolder) holder;
            Withdraw withdraw=mWithdrawList.get(position);
            crashHolder.mTxtCrashType.setTxtRight(withdraw.getBank_name());
            crashHolder.mTxtCrashMan.setTxtRight(withdraw.getAccount_name());
            crashHolder.mTxtCrashNum.setTxtRight(String.valueOf(withdraw.getMoney()+"元"));
            crashHolder.mTxtCrashAccount.setTxtRight(withdraw.getAccount_bank());
            crashHolder.mTxtCrashState.setTxtRight(getState(withdraw.getStatus()));
            crashHolder.mTxtCrashDate.setTxtRight(TransformUtil.timeFormat(withdraw.getAdd_time()));
            crashHolder.mTxtCrashRemark.setTxtRight(withdraw.getRemark());
        }
    }

    @Override
    public int getItemCount() {
        if (mType.equals(Const.TYPE_INCOME)) {
            return mCommissionList == null ? 0 : mCommissionList.size();
        } else {
            return mWithdrawList == null ? 0 : mWithdrawList.size();
        }
    }

    public void setCommissionList(List<Commission> commissionList) {
        mCommissionList = commissionList;
        notifyDataSetChanged();
    }

    public void setWithdrawList(List<Withdraw> withdrawList) {
        mWithdrawList = withdrawList;
        notifyDataSetChanged();
    }

    static class CrashHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.txt_crash_type)
        DoubleTextView mTxtCrashType;
        @BindView(R.id.txt_crash_man)
        DoubleTextView mTxtCrashMan;
        @BindView(R.id.txt_crash_num)
        DoubleTextView mTxtCrashNum;
        @BindView(R.id.txt_crash_account)
        DoubleTextView mTxtCrashAccount;
        @BindView(R.id.txt_crash_state)
        DoubleTextView mTxtCrashState;
        @BindView(R.id.txt_crash_date)
        DoubleTextView mTxtCrashDate;
        @BindView(R.id.txt_crash_remark)
        DoubleTextView mTxtCrashRemark;

        public CrashHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    static class CommissionHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.txt_commission_money)
        DoubleTextView mTxtCommissionMoney;
        @BindView(R.id.txt_commission_remark)
        DoubleTextView mTxtCommissionRemark;
        @BindView(R.id.txt_crash_time)
        DoubleTextView mTxtCrashTime;

        public CommissionHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
    private String getState(String state){
        String s="";
        switch (state) {
            case "0":
                s="申请中";
                break;
            case "1":
                s="申请成功";
                break;
            case "2":
                s="申请失败";
                break;
        }
        return s;
    }
}
